package com.ruoyi.station.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.station.domain.SDeviceProperties;
import com.ruoyi.station.mapper.SDevicePropertiesMapper;
import com.ruoyi.station.service.SDevicePropertiesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;

import java.security.Security;
import java.util.List;

/**
 * 设备属性Service业务层处理
 *
 * @author ruoyi
 * @date 2021-08-06
 */
@Slf4j
@Service
public class SDevicePropertiesServiceImpl extends ServiceImpl<SDevicePropertiesMapper, SDeviceProperties> implements SDevicePropertiesService {

    @Autowired
    private SDevicePropertiesMapper sDevicePropertiesMapper;
    /**
     * 导入设备属性数据
     * @param sDeviceProperties
     * @param updateSupport
     * @param username
     * @return
     */
    @Override
    public String importDeviceProperties(List<SDeviceProperties> sDeviceProperties, boolean updateSupport, String username) {
        if (StringUtils.isNull(sDeviceProperties) || sDeviceProperties.size() == 0)
        {
            throw new CustomException("导入设备属性数据不能为空！");
        }
        int i = 0;
        for (SDeviceProperties sDeviceProperty : sDeviceProperties) {
            sDeviceProperty.setCreateBy(username);
            i += sDevicePropertiesMapper.insert(sDeviceProperty);
        }
        return "成功导入"+i+"条";
    }
}
